<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="4" :lg="6" :md="8" :sm="54">
            <a-form-item :label="$t('时间')">
              <a-month-picker
                format="YYYY-MM"
                valueFormat="YYYY-MM"
                :placeholder="$t('请选择月份')"
                v-model="queryParam.month"
                style="width:100%"
              ></a-month-picker>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">{{$t('查询')}}</a-button>
              <a-button type="primary" style="margin-left: 8px" :loading="exloading" @click="handleExportXls($t('场地售耗币日报'))" v-has="'SiteCoinSummaryController:export'">{{
                $t('导出')
              }}</a-button>
            </span>
          </a-col>
          <template v-if="toggleSearchStatus"></template>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <!-- table区域-begin -->
    <div>
      <div>
        <a-table
          ref="table"
          size="middle"
          bordered
          rowKey="id"
          class="j-table-force-nowrap"
          :scroll="{ x: true }"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="false"
          :loading="loading"
          :customHeaderRow="customHeaderRow"
          :customRow="customRow"
        >
          <template slot="htmlSlot" slot-scope="text">
            <div v-html="text"></div>
          </template>
          <template slot="imgSlot" slot-scope="text">
            <span v-if="!text" style="font-size: 12px; font-style: italic">{{ $t('无图片') }}</span>
            <img
              v-else
              :src="getImgView(text)"
              height="25px"
              alt
              style="max-width: 80px; font-size: 12px; font-style: italic"
            />
          </template>
          <template slot="fileSlot" slot-scope="text">
            <span v-if="!text" style="font-size: 12px; font-style: italic">{{ $t('无文件') }}</span>
            <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">{{
              $t('下载')
            }}</a-button>
          </template>
        </a-table>
      </div>
    </div>
  </a-card>
</template>

<script>
import moment from 'moment'
import '@/assets/less/TableExpand.less'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'

export default {
  name: 'SiteSalescoinDailyReport',
  mixins: [JeecgListMixin],
  components: {},
  data() {
    return {
      moment,
      description: '场地售耗币日报表页面',
      // 表头
      columns: [
        {
          title: this.$t('日期'),
          align: 'center',
          dataIndex: 'date',
          customRender:(t,r)=>{
            if(t=='合计'){
              return this.$t(t)
            }
            return t
          }
        },
        {
          title: this.$t('会员充币'),
          align: 'center',
          dataIndex: 'rechCoin',
          customCell: (r, i) => {
            return {
              style: {
                textAlign: 'right',
              },
            }
          },
          customRender: (text, r) => {
            text = (text ==null || text =="" || text ==undefined)?0:parseFloat(text);
            return text.toFixed(2);
          }
        },
        {
          title: this.$t('售游戏币'),
          align: 'center',
          dataIndex: 'phyCoin',
          customCell: (r, i) => {
            return {
              style: {
                textAlign: 'right',
              },
            }
          },
          customRender: (text, r) => {
            text = (text ==null || text =="" || text ==undefined)?0:parseFloat(text);
            return text.toFixed(2);
          }
        },
        {
          title: this.$t('售限时币'),
          align: 'center',
          dataIndex: 'limitCoin',
          customCell: (r, i) => {
            return {
              style: {
                textAlign: 'right',
              },
            }
          },
          customRender: (text, r) => {
            text = (text ==null || text =="" || text ==undefined)?0:parseFloat(text);
            return text.toFixed(2);
          }
        },
        {
          title: this.$t('会员兑币'),
          align: 'center',
          dataIndex: 'exchCoin',
          customCell: (r, i) => {
            return {
              style: {
                textAlign: 'right',
              },
            }
          },
          customRender: (text, r) => {
            text = (text ==null || text =="" || text ==undefined)?0:parseFloat(text);
            return text.toFixed(2);
          }
        },
        {
          title: this.$t('会员投币'),
          align: 'center',
          dataIndex: 'slotCoin',
          customCell: (r, i) => {
            return {
              style: {
                textAlign: 'right',
              },
            }
          },
          customRender: (text, r) => {
            text = (text ==null || text =="" || text ==undefined)?0:parseFloat(text);
            return text.toFixed(2);
          }
        },
        {
          title: this.$t('其它'),
          align: 'center',
          dataIndex: 'otherCoin',
          customCell: (r, i) => {
            return {
              style: {
                textAlign: 'right',
              },
            }
          },
          customRender: (text, r) => {
            text = (text ==null || text =="" || text ==undefined)?0:parseFloat(text);
            return text.toFixed(2);
          }
        },
        {
          title: this.$t('总售币量'),
          align: 'center',
          dataIndex: 'saleCoin',
          customCell: (r, i) => {
            return {
              style: {
                textAlign: 'right',
              },
            }
          },
          customRender: (text, r) => {
            text = (text ==null || text =="" || text ==undefined)?0:parseFloat(text);
            return text.toFixed(2);
          }
        },
        {
          title: this.$t('总耗币量'),
          align: 'center',
          dataIndex: 'consumeCoin',
          customCell: (r, i) => {
            return {
              style: {
                textAlign: 'right',
              },
            }
          },
          customRender: (text, r) => {
            text = (text ==null || text =="" || text ==undefined)?0:parseFloat(text);
            return text.toFixed(2);
          }
        },
        {
          title: this.$t('差额'),
          align: 'center',
          dataIndex: 'diff',
          customCell: (r, i) => {
            return {
              style: {
                textAlign: 'right',
              },
            }
          },
          customRender: (text, r) => {
            text = (text ==null || text =="" || text ==undefined)?0:parseFloat(text);
            return text.toFixed(2);
          }
        },
      ],
      dataSources: [],
      queryParam: {
        month: moment().format('YYYY-MM'),
      },
      url: {
        list: '/report/day/siteCoinSummary/list',
        exportXlsUrl: '/report/day/siteCoinSummary/export',
      },
      isNoPageTotal: true,
    }
  },
  mounted() {},
  methods: {
    initDictConfig() {},
    customRow(r, i) {
      return {
        on: {
          click: () => {
            let x = this.selectedRowIndex.findIndex(r=>{return r=='a'+this.ipagination.current+''+i})
            if( x == -1 ){
              this.selectedRowIndex.push('a'+this.ipagination.current+''+i)
            }else{
              this.selectedRowIndex.splice(x, 1)
            }
          }
        },
        style: {
          whiteSpace: 'break-spaces',
          wordBreak: 'break-word',
          overflowWrap: 'break-word',
          backgroundColor: this.selectedRowIndex.findIndex(r=>{return r=='a'+this.ipagination.current+''+i}) > -1 ? '#FFECE6' : '',
          fontWeight: r.date == '合计' ? 700 : 400,
        },
      }
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>